// 生成 100 个企业数据的函数

/**
 * 回收地图-获取数据
 */
function apiGetInfo() {
  console.log("apiGetInfo");
  return new Promise((resolve) => {
    const res = {
      code: 200,
      data: {
        // 企业 {id: 1, name: '企业名称',  pos: [经度, 纬度]}
        enterprise: enterpriseList,
        // enterprise: [
        //   {
        //     uid: 1,
        //     comname: "宏宇塑料回收回收贸易公司",
        //     altX: 114.52570166494148,
        //     altY: 38.89367636496381,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "114.514169,38.043423",
        //   },
        //   {
        //     uid: 2,
        //     comname: "恒信废玻璃加工企业",
        //     altX: 114,
        //     altY: 38.5,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "114.514169,38.043423",
        //   },
        //   {
        //     uid: 3,
        //     comname: "丰泰再生资源加工企业111",
        //     altX: 114.23910591272005,
        //     altY: 38.376307074158674,
        //     commain: "废金属，废木材111",
        //     issm: 1,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 5,
        //     hangye: "二手设备>>工程机械111",
        //     rankimg: "https://style.feijiu.net/images/user/vip_zxhy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "114.514169,38.043423",
        //   },
        //   {
        //     uid: 4,
        //     comname: "华瑞再生资源回收有限公司",
        //     altX: 114.2,
        //     altY: 38.6,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "114.514169,38.043423",
        //   },
        //   {
        //     uid: 5,
        //     comname: "兴达废旧金属回收贸易公司",
        //     altX: 116.9520275488,
        //     altY: 38.13106868227,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "114.514169,38.043423",
        //   },
        //   {
        //     uid: 6,
        //     comname: "华瑞废旧物资回收中心",
        //     altX: 115.22216855565306,
        //     altY: 38.152576232292105,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "115.463612,38.875168",
        //   },
        //   {
        //     uid: 7,
        //     comname: "捷顺废旧金属处理公司",
        //     altX: 115.9472631977,
        //     altY: 38.8788910885,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "115.463612,38.875168",
        //   },
        //   {
        //     uid: 8,
        //     comname: "绿源电子废料回收中心",
        //     altX: 115.3740487755,
        //     altY: 38.43874102013,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "115.938396,39.819764",
        //     citylonglat: "115.463612,38.875168",
        //   },
        //   {
        //     uid: 9,
        //     comname: "兴达再生资源回收有限公司",
        //     altX: 116.28745755344399,
        //     altY: 39.715233013868364,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "116.411179,39.916747",
        //     citylonglat: "116.411179,39.916747",
        //   },
        //   {
        //     uid: 10,
        //     comname: "兴达再生资源回收中心",
        //     altX: 116.60053902285712,
        //     altY: 39.109565376137887,
        //     commain: "废金属，废木材",
        //     issm: 0,
        //     iszz: 1,
        //     ischat: 1,
        //     vipyear: 3,
        //     hangye: "二手设备>>工程机械",
        //     rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
        //     provlonglat: "116.411179,39.916747",
        //     citylonglat: "116.411179,39.916747",
        //   },
        // ],
        // 是否已经入驻 0: 未入驻 1: 已入驻
        is_join: 0,
      },
    };
    setTimeout(() => {
      resolve(res);
    }, 500);
  });
}

/**
 * 回收地图-提交信息
 * @param {*} name 联系人
 * @param {*} phone 联系电话
 */
function apiSubmit(data) {
  console.log("apiSubmit", data);
  return new Promise((resolve, reject) => {
    const res = { code: 200, msg: "提交成功" };
    setTimeout(() => {
      resolve(res);
    }, 500);
  });
}

/**
 * 留言询盘
 * @param {*} uid 公司id
 * @param {*} name 联系人
 * @param {*} phone 联系电话
 * @param {*} desc 补充内容
 */
function apiLeavaMessage(data) {
  console.log("apiLeavaMessage", data);
  return new Promise((resolve, reject) => {
    const res = { code: 200, msg: "提交成功" };
    setTimeout(() => {
      resolve(res);
    }, 500);
  });
}

/**
 * 获取用户信息
 */
function apiGetUserInfo() {
  return new Promise((resolve, reject) => {
    const res = {
      code: 200,
      msg: "获取成功",
      data: { name: "张三", phone: "13800138000" },
    };
    setTimeout(() => {
      resolve(res);
    }, 500);
  });
}

// ==============下面不用看，随机生成企业数据=============

// 生成随机偏移量的函数
function getRandomOffset() {
  // 偏移范围在 -0.5 到 0.5 之间，可按需调整
  return (Math.random() - 1) * 1;
}

// 生成企业名称的函数
function generateEnterpriseName() {
  const prefixes = [
    "宏宇",
    "捷顺",
    "绿源",
    "鑫盛",
    "丰泰",
    "兴达",
    "华瑞",
    "利达",
    "顺通",
    "恒信",
  ];
  const middle = [
    "废旧物资",
    "再生资源",
    "环保回收",
    "废旧金属",
    "塑料回收",
    "废纸回收",
    "电子废料",
    "废旧木材",
    "废玻璃",
    "废旧家电",
  ];
  const suffixes = [
    "回收有限公司",
    "回收中心",
    "回收贸易公司",
    "回收厂",
    "处理公司",
    "加工企业",
  ];

  const randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];
  const randomMiddle = middle[Math.floor(Math.random() * middle.length)];
  const randomSuffix = suffixes[Math.floor(Math.random() * suffixes.length)];

  return randomPrefix + randomMiddle + randomSuffix;
}
const length = 100;
function generateEnterprises(cities) {
  const enterprises = [];
  for (let i = 1; i <= length; i++) {
    // 随机选择一个城市
    const randomCity = cities[Math.floor(Math.random() * cities.length)];
    const enterprise = {
      uid: i,
      comname: generateEnterpriseName(),
      altX: randomCity.pos[0] + getRandomOffset(),
      altY: randomCity.pos[1] + getRandomOffset(),
      commain: "废金属，废木材",
      issm: 1,
      iszz: 1,
      ischat: 0,
      vipyear: 3,
      hangye: "二手设备>>工程机械",
      shopimuid: "feijiu1611938",
      rankimg: "https://style.feijiu.net/images/user/vip_viphy.png",
      provlonglat: randomCity.pos.join(","),
      citylonglat: randomCity.pos.join(","),
    };
    if (i === 1) {
      enterprise.pos = [];
    }
    enterprises.push(enterprise);
  }
  return enterprises;
}

const enterpriseList = generateEnterprises([
  { code: "110100", name: "北京市", pos: [116.4074, 39.9042] },
  { code: "120100", name: "天津市", pos: [117.1901, 39.1256] },
  { code: "130100", name: "河北省", pos: [114.4839, 38.0353] },
  { code: "140100", name: "山西省", pos: [112.5493, 37.8572] },
  { code: "150100", name: "内蒙古自治区", pos: [111.6708, 40.8184] },
  { code: "210100", name: "辽宁省", pos: [123.429, 41.7967] },
  { code: "220100", name: "吉林省", pos: [125.3245, 43.8868] },
  { code: "230100", name: "黑龙江省", pos: [126.6424, 45.7569] },
  { code: "310100", name: "上海市", pos: [121.4737, 31.2304] },
  { code: "320100", name: "江苏省", pos: [118.7806, 32.0402] },
  { code: "330100", name: "浙江省", pos: [120.1535, 30.2874] },
  { code: "340100", name: "安徽省", pos: [117.2781, 31.8611] },
  { code: "350100", name: "福建省", pos: [119.3062, 26.0753] },
  { code: "360100", name: "江西省", pos: [115.8921, 28.6764] },
  { code: "370100", name: "山东省", pos: [117.0009, 36.6758] },
  { code: "410100", name: "河南省", pos: [113.6654, 34.7579] },
  { code: "420100", name: "湖北省", pos: [114.3103, 30.5204] },
  { code: "430100", name: "湖南省", pos: [112.5493, 28.9382] },
  { code: "440100", name: "广东省", pos: [113.2644, 23.1291] },
  { code: "450100", name: "广西壮族自治区", pos: [108.3262, 22.824] },
  { code: "460100", name: "海南省", pos: [110.3311, 20.0319] },
  { code: "500100", name: "重庆市", pos: [106.5471, 29.5922] },
  { code: "510100", name: "四川省", pos: [104.0659, 30.6594] },
  { code: "520100", name: "贵州省", pos: [106.7134, 26.5784] },
  { code: "530100", name: "云南省", pos: [102.7123, 25.0406] },
  { code: "540100", name: "西藏自治区", pos: [91.1145, 29.6441] },
  { code: "610100", name: "陕西省", pos: [108.948, 34.2632] },
  { code: "620100", name: "甘肃省", pos: [103.8343, 36.0611] },
  { code: "630100", name: "青海省", pos: [101.7789, 36.6231] },
  { code: "640100", name: "宁夏回族自治区", pos: [106.2781, 38.4664] },
  { code: "650100", name: "新疆维吾尔自治区", pos: [87.6168, 43.7928] },
  { code: "710100", name: "台湾省", pos: [121.3065, 25.033] },
  { code: "810100", name: "香港特别行政区", pos: [114.1095, 22.2849] },
  { code: "820100", name: "澳门特别行政区", pos: [113.5486, 22.1967] },
]);
